package cn.usbtg.sutil;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * util:io
 */
public final class IOUtil {

    /**
     * 将InputStream读取为byte[]
     *
     * @param inputStream
     * @return
     */
    public static byte[] read(InputStream inputStream) {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buff = new byte[1024];
            int rc;
            while ((rc = inputStream.read(buff)) != -1) {
                byteArrayOutputStream.write(buff, 0, rc);
            }
            return byteArrayOutputStream.toByteArray();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}